package com.yizhubao.app.utils;

import com.yizhubao.app.beans.WXLoginBean;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.UUID;

import h.framework.pacy.utils.LogUtil;
import h.framework.pacy.utils.PreferencesUtil;
import h.framework.pacy.utils.StringUtil;

/**
 * @author Pacy.
 * Date: 2021/6/7/007
 * Time: 22:07
 * Mail pengwwe457621023@qq.com
 * Info
 */
public class Utils {
    /**
     * 格式化
     */
    private static DecimalFormat dfs = null;
    public static DecimalFormat format(String pattern) {
        if (dfs == null) {
            dfs = new DecimalFormat();
        }
        dfs.setRoundingMode(RoundingMode.FLOOR);
        dfs.applyPattern(pattern);
        return dfs;
    }

    /**
     * 是否登录
     * @return
     */
    public static boolean isLogin(){
       if(StringUtil.isEmpty((String) PreferencesUtil.get(Constants.USER_ID,""))){
            return false;
       }
       return true;
    }

    /**
     * 是否实名认证
     * @return
     */
    public static boolean isIdCard(){
        return (boolean) PreferencesUtil.get(Constants.HAS_IDCARD_VALID,false);
//        return false;
    }

    /**
     * 是否首次进入APP
     * @return
     */
    public static boolean isFirst(){
        return (boolean) PreferencesUtil.get(Constants.FIRST,true);
    }
    /**
     * 是否付款
     * @return
     */
    public static boolean isPay(){
        if(isSpecial()){
            return true;
        }
        return (boolean) PreferencesUtil.get(Constants.HAS_PAY,false);
//        return false;
    }

    /**
     * userid
     * @return
     */
    public static String getUserId(){
        return (String) PreferencesUtil.get(Constants.USER_ID,"");
//        return true;
    }

    /**
     * 是否有特殊身份
     * @return
     */
    public static boolean isSpecial(){
        return (boolean) PreferencesUtil.get(Constants.HAS_SPECIAL,false);
//        return false;
    }

    /**
     * 保存用户信息
     */
    public static void saveUser(WXLoginBean bean){
        PreferencesUtil.put(Constants.REAL_NAME,bean.getRealName());
        PreferencesUtil.put(Constants.USER_ID,bean.getId().toString());
        PreferencesUtil.put(Constants.HAS_PAY,bean.getHasPay());
        PreferencesUtil.put(Constants.HAS_IDCARD_VALID,bean.getHasIdCardValid());
        PreferencesUtil.put(Constants.HAS_SPECIAL,bean.getHasSpecialIdentity());
        PreferencesUtil.put(Constants.COOKIE,bean.getSessionId());
    }

    /**
     * 清除数据
     */
    public static void clearUser(){
        PreferencesUtil.put(Constants.REAL_NAME,"");
        PreferencesUtil.put(Constants.USER_ID,"");
        PreferencesUtil.put(Constants.HAS_PAY,false);
        PreferencesUtil.put(Constants.HAS_IDCARD_VALID,false);
        PreferencesUtil.put(Constants.HAS_SPECIAL,false);
        PreferencesUtil.put(Constants.COOKIE,"");
    }

    /**
     * 生成唯一标识  图片命名唯一标识
     *
     * @return
     */
    public static String getUUID(int type) {
        String s = UUID.randomUUID().toString();
        if(type==1){
            return s.replaceAll("-", "") + ".jpg";
        }
        return s.replaceAll("-", "") + ".mp4";
    }


}
